package midp;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;

public class MessageDialog extends Dialog implements CommandListener {

	public static final int OK = 0;
	protected Command command;
	protected Canvas canvas;
	private String message;
	private String label;

	private boolean showImage = false;


	public MessageDialog(Display display, String message) {
		this(display, message, null);
	}

	public MessageDialog(Display display, String amessage, String alabel) {
		super(display);
		this.message = (amessage == null) ? "完成" : amessage;
		this.label = (alabel == null) ? "确定" : alabel;
	}

	protected void init() {
		command = new Command(label, Command.OK, 1);
		canvas = showImage ? new WaitImageCanvas(message) : new DialogCanvas(
				message);
		canvas.addCommand(command);
		canvas.setCommandListener(this);
	}

	public void commandAction(Command c, Displayable d) {
		if (c == command) {
			doAction(OK);
		}
	}

	protected Displayable getDisplayable() {
		return canvas;
	}

	public boolean isShowImage() {
		return showImage;
	}

	public void setShowImage(boolean showImage) {
		this.showImage = showImage;
	}

}
